home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_014 / dimensions / matfinder.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  151 lines

  1. /* CREATE MATRICES FOR ROTATING OBJECTS (OF ANY DIMENSION) IN ANY DIMENSION */
  2.  
  3.  
  4.  
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #define SIZE 200
  8. #define TRUE 1
  9. #define FALS 0
  10. main()
  11. {
  12.     int i,j,k,n,c,r,u;
  13.     int KILL,MATS,NUM,TOP;
  14.     static char matr [10][6][6][SIZE];  /* Note: Array size and data set here is designed for use in 4-d matrices */
  15.     static char data [10][ 5] = {"tz","ty","tx","zy","zx","yx"};
  16.     static char pers [10][ 5] = {"  ","  ","P1","P2","P3","P4","P5","P6"};
  17.     static char tess [ 6] [6][SIZE];
  18.     static char temp [SIZE];
  19.     char *p,*q,*s,*t,*s1,*t1;
  20.  
  21. printf ("This program creates matrices for multidimensional rotations\n");
  22. printf ("This program is presently set for four dimensions\n");n=4;
  23.     
  24. /* Prepare array space for matrices */
  25.     KILL = n-2;                /*  KILLer matrices remove higher dimensionality from end matrix, redundant for display */
  26.     MATS = (n-1)*n/2;          /*  MATriceS needed which when multiplied together will form final matrix               */
  27.     NUM  = MATS+KILL;          /*  NUMber of arrays needed by the program to preform the manipulations                 */
  28.     TOP  = n+1;                /*  TOP spatial size needed                                                             */
  29.  
  30. printf ("Number of Matrices = %d\n",MATS);
  31. printf ("Number of kills    = %d\n",KILL);
  32. printf ("Total Matrices     = %d\n",NUM );
  33.  
  34.  
  35. /* THE MATRIX ARRAYS */
  36.  
  37. printf ("Initializing Matrices\n");
  38.  
  39. /* Initialization of matrices */
  40.     for (i=0;i<NUM;++i)
  41.  {                              /* My mats have a null char for 0 */
  42.          for (j=0;j<TOP;++j)    /* and a space for one            */
  43.       {
  44.               strcpy(matr [ i ][ j ][ j ], " ");
  45.               strcpy(tess [ j ][ j ], " ");
  46.       }
  47.  }
  48. printf ("Now making Killer matrices\n");
  49. printf ("Perspective variables introduced here also\n");
  50.     if  (!KILL)
  51.  {
  52.          printf ("Its 2-d already!");
  53.          goto overlord;
  54.  };
  55.     KILL=2;
  56.     for (i=MATS;i<NUM;++i)
  57.  {
  58.          strcpy (matr [ i ][KILL][KILL],"");
  59.          strcpy (matr [ i ][KILL][TOP-1],pers [KILL]);
  60.          ++KILL;
  61.  }
  62.  
  63.  
  64.  
  65. overlord:
  66. printf ("The OVERLORD MATRIX\n");
  67.  
  68. /* THE OVERLORD MATRIX CREATOR */
  69.     k=0;
  70.     for (i=0;i<(n-1);++i)
  71.  {
  72.          for (j=(i+1);j<n;++j)
  73.       {
  74.               p=data [k];
  75.               q=matr [ k ][ i ][ i ];strcpy(q,"C");strcat(q,p);  /* COS */
  76.               q=matr [ k ][ j ][ j ];strcpy(q,"C");strcat(q,p);  /* COS */
  77.               q=matr [ k ][ i ][ j ];strcpy(q,"S");strcat(q,p);  /* SIN */
  78.               q=matr [ k ][ j ][ i ];strcpy(q,"N");strcat(q,p);  /* NIS */
  79.               ++k;
  80.       }
  81.  }
  82.  
  83. printf ("Now displaying Matrices\n");
  84.  
  85. /* Matrix Display */ 
  86.     for (i=0;i<NUM;++i)
  87.  {
  88.          printf ("Now Displaying Matrix #%d\n\n",i+1);
  89.          for (k=0;k<TOP;++k)
  90.       {
  91.               for (j=0;j<TOP;++j)
  92.            {
  93.                    printf (" %s",matr [ i ][ k ][ j ]);
  94.                    if (j<TOP-1)printf (",");
  95.            }
  96.               printf ("\n");
  97.       }
  98.  }
  99.  
  100.  
  101. printf ("Now Multiplying Matrices!\n");
  102.  
  103.     for (n=0;n<NUM;++n)
  104.  {
  105.          printf ("\n\nmatrix #%d\n",(n+1));
  106.          for (c=0;c<TOP;++c)
  107.       {
  108.               for (r=0;r<TOP;++r)
  109.            {         /* Update true matrix from temporary */
  110.                    strcpy (matr [NUM][c][r], tess [c][r]);
  111.            }
  112.       }
  113.  
  114.          for (c=0;c<TOP;++c)                    /* COLUMN */
  115.       {
  116.               for (r=0;r<TOP;++r)                   /* ROW */
  117.            {
  118.                      /* Reset Temporary row of matrix */
  119.                    strcpy (temp,"");
  120.                    for (i=0;i<TOP;++i)                 /* POSITION IN ROW */
  121.                 {
  122.                         if (*(p=matr [NUM][c][i]) != 0 && *(q=matr [n][i][r]) !=0)
  123.                      {
  124.                             if (*p==' ' && *q==' '){strcpy(temp," ");goto SKIP;};
  125.  
  126.                             s=stpchr(p,'(');s1=strrchr(p,')');
  127.                               t=stpchr(p,'+');t1=strrchr(p,'+');
  128.                                 u=!(t>=s && t1<=s1);
  129. /* Look for '+' signs in eqn. and bracket if multiplied */
  130.                                 if (strlen(temp)>1)
  131.                                     strcat(temp,"+");
  132.                                 if (*p==' '){strcat(temp,q);goto SKIP;};
  133.                                 if (*q==' '){strcat(temp,p);goto SKIP;};
  134.                                 if (u==TRUE)strcat(temp,"(");
  135.                               strcat(temp,p);
  136.                                 if (u==TRUE)strcat(temp,")");
  137.                               strcat(temp,q);
  138. SKIP:
  139.             ;    /* Manx needs null statement at label */
  140.                      }
  141.                 }
  142.  
  143.                    strcpy (tess [c][r],temp);
  144.                    if (r<TOP)printf ("%s,",temp);
  145.                         else printf ("%s",temp);
  146.            }
  147.               printf ("\n\n");
  148.       }
  149.  }
  150. }
  151.